/*
 * @Author: dmyang
 * @Date:   2015-08-31 21:17:45
 * @Last Modified by:   dmyang
 * @Last Modified time: 2016-03-28 09:48:22
 */

'use strict'

import 'commonCss'



// 直接使用npm模块

require('../css/main.css')
require('../css/swiper.min.css')
require('../js/lib/swiper.min.js')

let report = require('./helpers/report')
let bar = require('./helpers/bar')
let url = require('./utils/url')
let $ajax = require('./helpers/ajax')
require('./utils/site')

let tpl = site.tpl('main')

var param = {
    id : '',
    ind : '',
    typeId : '',
    productId : ''
}


function handler () {
    site.getToken(render)
}

function render(){
    site.setNav(main)
    site.header()
    site._ajax({
        type:'GET',
        url: HTTP_SERVER + 'cms/api/websites/89060613317206016',
        data:{},
        success: function (res) {
            site.footer(res)
        }
    })
}
site.render = main
site.renderList = renderList
function main (pageId,proId,typeId) {
    param.id = pageId?pageId:(site.id?site.id:site.QueryString('id'))
    param.ind = site.getInd(param.id)
    param.productId = proId?proId:site.QueryString('productId')
    param.typeId = typeId?typeId:site.QueryString('typeId')
    renderList(0)
}

function renderList (pageInd) {
    site._ajax({
        type:'GET',
        url:HTTP_SERVER+'information/api/categories/'+param.typeId+'/information',
        data:{page:pageInd,size:6,sort:'displayOrder,desc'},
        success: function(res){
            let arr = []
            for(let i = 0; i < res.totalPages; i++){
                arr[i] = i
            }
            let page = {totalPages:arr,number:res.number}
            site.banner('108267392076926976',{type:site.type,id:param.id,nav:site.nav[param.ind],page:1,list:res.content,page:page})
            site.menuHide()
        }
    })
}

document.addEventListener('visibilitychange', handler)
window.addEventListener('DOMContentLoaded', handler)
window.addEventListener('resize', handler)
